﻿#light

module PubSim.Chocolate

open System
open Microsoft.FSharp.Control

/// Chocolate type definition ... used to set status of whether chocolate is on the
/// shelf or not.
type Chocolate(initValue) =
    let mutable chocolate = initValue
    let lockObj = new Object()

    member c.AddChocolateToCupboard() =
        chocolate <- true
        ignore()
    member c.FetchChocolateFromCupboard() =
        lock lockObj (fun() ->
            if chocolate = true then
                chocolate <- false
                true
            else
                false
        )
    member c.IsChocolateInCupboard() =
        chocolate
